#!/bin/bash

print_usage()
{
    local script_name

    # Get the script name
    script_name=${0##*/}

    # Echo usage info
    echo " "
    echo " "${script_name}
    echo " "
    echo " Usage: Clear all files recursively"
    echo "   ${script_name} src_dir mode"
    echo " "
    echo " "

    # Exit with non-zero exit status
    exit 1
}

main()
{
    # Check the number of argements
    if [ $# != "1" ]; then
        print_usage
    fi

    # local variables
    script_name=${0##*/}
    src_dir="$1"

    # Check src file
    if [ ! -d "${src_dir}" ]; then
        echo "${script_name}: Source directory does not exist (${src_dir})."
        exit 1
    fi

    files="$(find ${src_dir} -name "#*") $(find ${src_dir} -name "*~")"
    for file in ${files}; do
        echo "${file}"
    done

    echo "Delete above files ? (y/n)"
    read line

    if test "${line}" = "y" || test "${line}" = "Y"; then 
        for file in ${files}; do
            echo "Deleting ... ${file}"
            /bin/rm -f ${file}
        done
    fi
    return 0
}

main "$@"